package com.ht.medicaltreatment.activity

import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.view.View
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener

import com.gym.baselib.base.BaseActivity
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.adapter.OrderList96Adapter
import com.ht.medicaltreatment.bean.OrderList96Bean
import com.ht.medicaltreatment.viewmodel.OrderList96ViewModel
import com.xgst.lib.utils.showToast
import kotlinx.android.synthetic.main.activity_96_order_list_layout.*

class NinetySixeOrderListActivity:BaseActivity(), OnItemClickListener {
    private val model by viewModels<OrderList96ViewModel>()
    private lateinit var adapter:OrderList96Adapter

    override fun getLayoutId() = R.layout.activity_96_order_list_layout

    override fun init() {
        setTitle("96孔核验订单列表")
        recyclerView.layoutManager = LinearLayoutManager(this)
        adapter = OrderList96Adapter()
        recyclerView.adapter = adapter
        adapter.setOnItemClickListener(this)
    }

    override fun onResume() {
        super.onResume()
        showProgress()
        model.orderList({
            dismissProgress()
            if(it == null){
                tvOrderCount.text = "订单总数: 0"
            }else{
                tvOrderCount.text = "订单总数: ${it.size}"
            }
            adapter.setNewInstance(it)
        },{
            dismissProgress()
            showToast(it)
        })
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
        if(Build.MODEL == "V9100" || packageManager.hasSystemFeature(PackageManager.FEATURE_NFC) && Build.MODEL != "C72"){
            val item = adapter.getItem(position) as OrderList96Bean
            val intent = Intent(this,NinetySixDetailActivity::class.java)
            intent.putExtra("id",item.id)
            intent.putExtra("version",Build.MODEL == "V9100")
            startActivity(intent)
        }else{
            showToast("该设备不允许使用此功能")
        }

    }
}